package org.bluesky.controller;

import org.bluesky.framework.ResponseResult;
import org.bluesky.framework.dto.TagListDto;
import org.bluesky.framework.entity.Comment;
import org.bluesky.framework.entity.Tag;
import org.bluesky.framework.service.TagService;
import org.bluesky.framework.utils.BeanCopyUtils;
import org.bluesky.framework.vo.PageVo;
import org.bluesky.framework.vo.TagVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @GetMapping("/list")
    public ResponseResult<PageVo> list(Integer pageNum, Integer pageSize, TagListDto tagListDto){
        return tagService.pageTageList(pageNum,pageSize,tagListDto);
    }

    @PostMapping("")
    public ResponseResult addTag(@RequestBody TagListDto tagListDto){
        Tag tag = BeanCopyUtils.copyBean(tagListDto, Tag.class);
        return tagService.addTag(tag);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteTag(@PathVariable("id")Long id){
        return tagService.deleteTagById(id);
    }

    @GetMapping("/{id}")
    public ResponseResult getTag(@PathVariable("id")Long id){
        return tagService.getTagById(id);
    }

    @PutMapping("")
    public ResponseResult updateTag(@RequestBody TagVo tagVo){
        return tagService.updateTagById(tagVo);
    }

    @GetMapping("/listAllTag")
    public ResponseResult listAllTag(){
        return tagService.listAllTag();
    }
}
